package com.tangding.aspect.god.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.tangding.aspect.god.GodAspect;
import com.tangding.hprose.api.server.command.impl.user.GetUsers;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年12月23日_上午9:23:44
 *
 */
@Component
@Aspect
public class GetUsersAspect extends GodAspect {
	
	@Around(value = "execution(public * com.tangding.hprose.api.server.command.impl.user.GetUsers.exe(..))")
	public Object godPrcess(ProceedingJoinPoint pjp) throws Throwable {
		Map<String, Object> map = getUserInfo(pjp);
		String uid = map.get("uid").toString();
		
		if (!godAccount.equals(uid)) {//普通用户
			return pjp.proceed();
		}else {
			List<Map<String, Object>> vos = new ArrayList<>();
			userRepository.getUserMap().values().forEach(user -> {
				if (!godAccount.equals(user.getUid())) {
					vos.add(GetUsers.findPermissions(user));
				}
			});
			return doResponseSucc(vos);
		}
	}
}
